<?php

namespace app\controller\admin;

use app\BaseController;
use think\facade\Db;

class MenuController extends BaseController
{
    public function doEdit()
    {

        $result = input("");
        $id = '';
        foreach ($result['meta'] as $key => $row) {
            $result[$key] = $row;
        }
        unset($result['meta']);

        if (isset($result['id'])) {
            $id = $result['id'];
            unset($result['id']);
        }

        if (isset($result['children'])) {
            unset($result['children']);
        }
        if (isset($result['levelHidden'])) {
            unset($result['levelHidden']);
        }
        if (isset($result['isCustomSvg'])) {
            unset($result['isCustomSvg']);
        }
        if (isset($result['tabHidden'])) {
            unset($result['tabHidden']);
        }
//
        if ($id) {
            Db::name("menu")->where("id", $id)->update($result);
        } else {
            Db::name("menu")->insert($result);
        }
       return  retJson();


    }

    public function doDelete()
    {
        $result = input("paths");
        Db::name("menu")->where("path", $result)->delete();

        return retJson();
    }

}
